package com.lx.Login;


import com.lx.Login.bean.LoginPropertise;
import com.lx.Login.web.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@AutoConfiguration
@ComponentScan("com.lx.Login")
//  matchIfMissing = true        没有enable 默认打开
@ConditionalOnProperty(prefix = "login", name = "enable", matchIfMissing = true)
@EnableConfigurationProperties(LoginPropertise.class)
public class LoginConfigration implements WebMvcConfigurer {

    @Autowired
    LoginPropertise propertise;
    @Autowired
    LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(loginInterceptor).addPathPatterns(propertise.getLoginScope());

        if (propertise.getLoginScope().length > 0 && propertise.getLoginScope() != null) {
            registry.addInterceptor(loginInterceptor)
                    .addPathPatterns(propertise.getLoginScope());
        }
    }
}
